// componentinfowidget.cpp
#include "componentinfowidget.h"
#include <QVBoxLayout>

ComponentInfoWidget::ComponentInfoWidget(QWidget *parent) : QWidget(parent)
{
    QVBoxLayout *layout = new QVBoxLayout(this);

    formLayout = new QFormLayout();

    nameLabel = new QLabel(tr("Name:"));
    nameEdit = new QLineEdit();
    nameEdit->setReadOnly(true);
    formLayout->addRow(nameLabel, nameEdit);

    typeLabel = new QLabel(tr("Type:"));
    typeEdit = new QLineEdit();
    typeEdit->setReadOnly(true);
    formLayout->addRow(typeLabel, typeEdit);

    valueLabel = new QLabel(tr("Value:"));
    valueEdit = new QLineEdit();
    formLayout->addRow(valueLabel, valueEdit);

    descriptionLabel = new QLabel(tr("Description:"));
    descriptionEdit = new QTextEdit();
    descriptionEdit->setReadOnly(true);
    formLayout->addRow(descriptionLabel, descriptionEdit);

    connectionsLabel = new QLabel(tr("Connections:"));
    connectionsEdit = new QTextEdit();
    connectionsEdit->setReadOnly(true);
    formLayout->addRow(connectionsLabel, connectionsEdit);

    layout->addLayout(formLayout);
    layout->addStretch();
}

void ComponentInfoWidget::showComponentInfo(Component *component)
{
    if (!component) return;

    nameEdit->setText(component->name());
    typeEdit->setText(component->typeString());
    valueEdit->setText(component->value());
    descriptionEdit->setText(component->description());

    // 显示连接信息
    QString connections;
    // 这里应该显示组件的连接情况
    connectionsEdit->setText(connections);
}
